package com.llt.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import org.springframework.core.env.Environment;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import org.springframework.core.env.Profiles;
@Configuration
public class SwaggerConfig {
    /**
     * http://localhost:8001/swagger-ui/index.html
     * @return
     */
    @Bean
    public Docket user(Environment environment){
        //设置现实swagger 环境
        Profiles of = Profiles.of("dev", "test");
        //通过environment.acceptsProfiles(of 获取当前是否在上面设置的环境
        boolean flag = environment.acceptsProfiles(of);
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())//基础配置信息
                .groupName("用户开源导航")
                .enable(flag)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.llt.user.controller"))

               .build();
    }
    @Bean
    public Docket admin(Environment environment) {
        //设置现实swagger 环境
        Profiles of = Profiles.of("dev", "test");
        //通过environment.acceptsProfiles(of 获取当前是否在上面设置的环境
        boolean flag = environment.acceptsProfiles(of);
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo())//基础配置信息

                .groupName("吞吐行后台管理")
                .enable(flag)
                .select()
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .apis(RequestHandlerSelectors.basePackage("com.llt.controller"))
//                .paths(PathSelectors.ant("/llt/controller/**"))
                .build();

    }
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("刘蓝天web演示接口")
                .description("用于测试")
                .contact(new Contact("llt", "127.0.0.1:8080/swagger", "229236940@qq.com"))
                .version("1.0")
                .build();

    }
}
